<?php
namespace App\Http\Controllers\System;

use App\Http\Controllers\Controller;
use App\Models\MBonusLog;
use App\Models\MConsumeLog;
use App\Models\MNotices;
use App\Models\MRemitLog;
use App\Models\MSwitchCoinLog;
use App\Models\MTransferLog;
use App\Models\MUser;
use App\Models\MUserAttr;
use App\Models\MWallet;
use App\Models\MWithdrawLog;
use App\Templates\ActivationUserAct;
use App\Templates\DelUserAct;
use App\Templates\RegUserAct;
use App\Utils\GDUtil;
use App\Utils\TreeUtil;
use DB;
use Exception;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Mail;

/**
 * 会员控制器
 */
class UserController extends Controller
{
    use RegUserAct, ActivationUserAct, DelUserAct;

    /**
     * 会员登录界面
     */
    public function loginPage()
    {
        $this->data['theme'] = loginTheme();
        return view('system.login')->with($this->data);
    }

    /**
     * 用户登录验证
     */
    public function loginAct(Request $request)
    {
        if (!$this->validateReq($request, MUser::loginRulesWithMsg(0), MUser::loginRulesWithMsg(1))) {
            $this->data = $this->makeJsCode(1, $this->errors->first());
            return response()->json($this->data);
        }

        //验证码检查
        if (!GDUtil::checkCode(GDUtil::$USER_CODE, $request->yzm)) {
            $this->refreshYZM();
            $this->data = $this->makeJsCode(1, "验证码效验失败！");
            return response()->json($this->data);
        }

        //账号密码检查
        $user = MUser::where("username", strtolower($request->username))
            ->where("userpass", $request->userpass)->first();
        if (empty($user)) {
            $this->refreshYZM();
            $this->data = $this->makeJsCode(1, "账号密码验证失败！");
            return response()->json($this->data);
        }

        $user->loginStatus()->loginLog();
        $this->data = $this->makeJsCode(0, "登录成功！");
        return response()->json($this->data);
    }

    /**
     * 我的个人主页页面
     */
    public function centerPage(Request $request)
    {
        $this->data['user'] = MUser::find(ss('uid'));

        $this->data['notices'] = MNotices::select(['id', 'title', 'time', 'start', 'end'])->where('end', '>', time())->orderBy("time", "desc")->skip(0)->take(7)->get();

        return view("system.center")->with($this->data);
    }

    /**
     * 奖金记录页面
     */
    public function bonusPage($index = 1)
    {
        $this->fyInit(route("sys.bonus"), 20)->fyCalc(MBonusLog::where('uid', ss('uid'))->count(), $index);
        $bonus = MBonusLog::where('uid', ss('uid'))->skip($this->fy_pgOffset)->take($this->fy_pgSize)->get();
        $this->data['bonus'] = $bonus;

        $this->fyViewInit($this->data);
        return view('system.bonus')->with($this->data);
    }

    /**
     * 消费记录页面
     */
    public function shoppingPage($index = 1)
    {
        $this->fyInit(route('sys.shopping'), 20)->
        fyCalc(MConsumeLog::where('uid', ss('uid'))->count(), $index);
        $logs = MConsumeLog::where('uid', ss('uid'))->orderBy('time', 'desc')
            ->skip($this->fy_pgOffset)->take($this->fy_pgSize)->get();
        $this->data['logs'] = $logs;

        $this->fyViewInit($this->data);
        return view('system.shopping')->with($this->data);
    }

    /**
     * 会员转账页面
     */
    public function transferPage()
    {
        $this->data['wallet'] = MWallet::where('uid', ss('uid'))->first();
        return view('system.transfer')->with($this->data);
    }

    /**
     * 会员转账处理
     */
    public function transferAct(Request $request)
    {
        if (count($request->rule) > 0) {//验证自动添加的属性规则
            for ($i = 0; $i < count($request->rule); $i++) {
                $rule = unserialize($request->rule[$i]);
                $msg = unserialize($request->msg[$i]);
                if (!$this->validateReq($request, $rule, $msg)) {
                    $this->data = $this->makeJsCode(1, $this->errors->first());
                    return response()->json($this->data);
                }
            }
        }

        //对会员转账信息进行验证
        if (!$this->validateReq($request, MWallet::transferValidate(0), MWallet::transferValidate(1))) {
            $this->data = $this->makeJsCode(1, $this->errors->first());
            return response()->json($this->data);
        }

        //检查接收用户（已激活）是否存在，并且不能给自己转账
        $accept_user = MUser::where('username',strtolower($request->accept_user) )->first();
//            ->where('ok_status', MUser::$STATUS_ACTIVATED);

        if (empty($accept_user) || strtolower(ss('uname')) == $accept_user->username) {
            $this->data = $this->makeJsCode(1, "接收用户不存在!");
            return response()->json($this->data);
        }

        //检查转账金额是否合法
        if ($request->money <= 0  || $request->money % 100 != 0) {
            $this->data = $this->makeJsCode(1, "转账金额必须为100的整数倍！");
            return response()->json($this->data);
        }

        //检查交易密码
        $me = MUser::find(ss('uid'));
        if ($request->safepass != $me->safepass) {
            $this->data = $this->makeJsCode(1, "交易密码错误!");
            return response()->json($this->data);
        }

        $me_wallet = $me->wallet;
        //检查钱包余额是否充足
        if ($request->wallet == MWallet::$WALLET_TYPE_1 && $request->money > $me_wallet->w1) {
            $this->data = $this->makeJsCode(1, "奖金币余额不足！");
            return response()->json($this->data);
        } elseif ($request->wallet == MWallet::$WALLET_TYPE_2 && $request->money > $me_wallet->w2) {
            $this->data = $this->makeJsCode(1, "报单币余额不足！");
            return response()->json($this->data);
        } elseif ($request->wallet == MWallet::$WALLET_TYPE_3 && $request->money > $me_wallet->w3) {
            $this->data = $this->makeJsCode(1, "购物币余额不足！");
            return response()->json($this->data);
        }

        //进行转账操作
        try {
            DB::transaction(function () use (&$me, &$me_wallet, &$accept_user, &$request) {
                if (MWallet::transferMoney($me, $me_wallet, $accept_user, $accept_user->wallet,
                        $request->wallet, $request->money) && MUserAttr::userInfo($me->id, $request->all())
                ) {
                    $this->data = $this->makeJsCode(0, "转账成功！");
                } else {
                    $this->data = $this->makeJsCode(1, "转账失败！");
                }
            });
        } catch (Exception $exception) {
            $this->data = $this->makeJsCode(1, "转账失败！");
        }
        return response()->json($this->data);
    }

    /**
     * 转账日志
     */
    public function tranLogPage(Request $request, $index = 1)
    {
        //开启分页
        $this->fyInit(route("sys.transfer.log"), 20)->fyCalc(MTransferLog::where('uid', ss('uid'))
            ->orWhere('accept_id', ss('uid'))->count(), $index);
        $this->data['transferLogs'] = MTransferLog::where('uid', ss('uid'))
            ->orWhere('accept_id', ss('uid'))
            ->skip($this->fy_pgOffset)
            ->take($this->fy_pgSize)
            ->orderBy('time', 'desc')
            ->get();
        $this->fyViewInit($this->data);

        return view('system.transfer_logs')->with($this->data);
    }

    /**
     * 会员提现界面
     */
    public function withdrawPage()
    {
        $this->data['wallet'] = MWallet::where('uid', ss('uid'))->first();
        return view('system.withdraw')->with($this->data);
    }

    /**
     * 会员提现执行函数
     */
    public function withdrawAct(Request $request)
    {
        if (count($request->rule) > 0) {//验证自动添加的属性规则
            for ($i = 0; $i < count($request->rule); $i++) {
                $rule = unserialize($request->rule[$i]);
                $msg = unserialize($request->msg[$i]);
                if (!$this->validateReq($request, $rule, $msg)) {
                    $this->data = $this->makeJsCode(1, $this->errors->first());
                    return response()->json($this->data);
                }
            }
        }

        //对会员提现信息进行验证
        if (!$this->validateReq($request, MWithdrawLog::withdrawRulMsg(0), MWithdrawLog::withdrawRulMsg(1))) {
            $this->data = $this->makeJsCode(1, $this->errors->first());
            return response()->json($this->data);
        }
        MUserAttr::userInfo(1, $request);
        //验证交易密码
        $me = MUser::find(ss('uid'))->first();
        if ($request->safepass != $me->safepass) {
            $this->data = $this->makeJsCode(1, "交易密码验证失败！");
            return response()->json($this->data);
        }

        //检查钱包余额是否充足
        $me_wallet = $me->wallet;
        if ($request->wallet == MWallet::$WALLET_TYPE_1 && $request->money > $me_wallet->w1) {
            $this->data = $this->makeJsCode(1, "提现失败，奖金币余额不足");
            return response()->json($this->data);
        } elseif ($request->wallet == MWallet::$WALLET_TYPE_2 && $request->money > $me_wallet->w2) {
            $this->data = $this->makeJsCode(1, "提现失败，报单币余额不足");
            return response()->json($this->data);
        } elseif ($request->wallet == MWallet::$WALLET_TYPE_3 && $request->money > $me_wallet->w3) {
            $this->data = $this->makeJsCode(1, "提现失败，购物币余额不足");
            return response()->json($this->data);
        }

        try {
            DB::transaction(function () use (&$request, &$me, $me_wallet) {
                if ($me_wallet->withdraw($request->wallet, $request->money, $request->intro) && MUserAttr::userInfo($me->id, $request->all())) {
                    $this->data = $this->makeJsCode(0, "申请提现成功！");

                } else {
                    DB::rollBack();
                    $this->data = $this->makeJsCode(1, "申请提现失败！");
                }
            });
        } catch (Exception $exception) {
            $this->data = $this->makeJsCode(1, "申请提现失败！");
        }

        return response()->json($this->data);
    }

    /**
     * 提现日志界面
     */
    public function withdrawLogPage(Request $request, $index = 1)
    {
        //开启分页
        $this->fyInit(route("sys.withdraw.log"), 20)->fyCalc(MWithdrawLog::where('uid', ss('uid'))->count(), $index);
        $this->data['withdrawLogs'] = MWithdrawLog::where('uid', ss('uid'))
            ->skip($this->fy_pgOffset)
            ->take($this->fy_pgSize)
            ->orderBy('time', 'desc')
            ->get();
        $this->fyViewInit($this->data);

        return view('system.withdraw_logs')->with($this->data);
    }

    /**
     * 币种转换申请页
     */
    public function switchCoinPage()
    {
        $this->data['wallet'] = MWallet::where('uid', ss('uid'))->first();
        return view('system.switch_coin')->with($this->data);
    }

    /**
     * 币种转换执行函数
     */
    public function switchCoinAct(Request $request)
    {
        //对会员币种转换信息进行验证
        if (!$this->validateReq($request, MSwitchCoinLog::withdrawRulMsg(0), MSwitchCoinLog::withdrawRulMsg(1))) {
            $this->data = $this->makeJsCode(1, $this->errors->first());
            return response()->json($this->data);
        }

        //同币种之间禁止转换
        if ($request->real_coin == $request->final_coin) {
            $this->data = $this->makeJsCode(1, "同币种禁止转换! ");
            return response()->json($this->data);
        }

        //检查交易密码
        $me = MUser::find(ss('uid'));
        if ($request->safepass != $me->safepass) {
            $this->data = $this->makeJsCode(1, "交易密码错误!");
            return response()->json($this->data);
        }

        //检查钱包余额是否充足
        $wallet = $me->wallet;
        if ($request->real_coin == MWallet::$WALLET_TYPE_1 && $request->money > $wallet->w1) {
            $this->data = $this->makeJsCode(1, "转换失败，奖金币余额不足！");
            return response()->json($this->data);

        } elseif ($request->real_coin == MWallet::$WALLET_TYPE_2 && $request->money > $wallet->w2) {
            $this->data = $this->makeJsCode(1, "转换失败，报单币余额不足！");
            return response()->json($this->data);

        } elseif ($request->real_coin == MWallet::$WALLET_TYPE_3 && $request->money > $wallet->w3) {
            $this->data = $this->makeJsCode(1, "转换失败，购物币余额不足！");
            return response()->json($this->data);
        }

        if ($wallet->coinSwitch($request->real_coin, $request->final_coin, $request->money)) {
            MSwitchCoinLog::log($me->id, $request->real_coin, $request->final_coin, $request->money, 0, $request->money);
            $this->data = $this->makeJsCode(0, "币种转换成功！");
        } else {
            $this->data = $this->makeJsCode(1, "币种转换失败！");
        }

        return response()->json($this->data);
    }

    /**
     * 币种转换记录
     */
    public function switchLogPage(Request $request, $index = 1)
    {
        //开启分页
        $this->fyInit(route("sys.switch.log"), 20)->fyCalc(MSwitchCoinLog::where('uid', ss('uid'))->count(), $index);
        $this->data['switchLogs'] = MSwitchCoinLog::where('uid', ss('uid'))
            ->skip($this->fy_pgOffset)
            ->take($this->fy_pgSize)
            ->orderBy('time', 'desc')
            ->get();
        $this->fyViewInit($this->data);

        return view('system.switch_logs')->with($this->data);
    }

    public function remitApply()
    {
        $this->data['user'] = MUser::find($_SESSION['uid']);
        return view('system.remit_apply')->with($this->data);
    }

    /**
     * 验证并保存一条打款申请单
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function remitSave(Request $request)
    {
        //对打款申请单信息进行验证
        if (!$this->validateReq($request, MRemitLog::editRulesWithMsg(0), MRemitLog::editRulesWithMsg(1))) {
            $this->data = $this->makeJsCode(1, $this->errors->first());
            return response()->json($this->data);
        }

        //检查打款金额
        if ($request->money <= 0) {
            $this->data = $this->makeJsCode(1, "投资金额请必须为大于0的数字！");
            return response()->json($this->data);
        }

        //验证时间日期是否合法
        $time = strtotime($request->time) ? strtotime($request->time) : false;
        if ($time === false) {
            $this->data = $this->makeJsCode(1, "请填写合法的时间日期格式！");
            return response()->json($this->data);
        }

        //验证收款方式
        if ($request->remit_type == MWithdrawLog::$PAY_TYPE_YHK) {
            if (!$request->has(['card_no', 'card_addr', 'card_name'])) {
                $this->data = $this->makeJsCode(1, "请完善银行卡打款信息！");
                return response()->json($this->data);
            }
            $info = "银行卡号：$request->card_no" . "，开户行地址：$request->card_addr" . "，开户人姓名：$request->card_name";
        }
        if ($request->remit_type == MWithdrawLog::$PAY_TYPE_ZFB) {
            if (!$request->has(['alipay_no', 'alipay_name'])) {
                $this->data = $this->makeJsCode(1, "请完善支付宝打款信息！");
                return response()->json($this->data);
            }
            $info = "支付宝帐号：$request->alipay_no" . "，支付宝开户人姓名：$request->alipay_name";
        }
        if ($request->remit_type == MWithdrawLog::$PAY_TYPE_WX) {
            if (!$request->has(['wechat_no', 'wechat_name'])) {
                $this->data = $this->makeJsCode(1, "请完善微信打款信息！");
                return response()->json($this->data);
            }
            $info = "微信帐号：$request->wechat_no" . "，微信开户人姓名：$request->wechat_name";
        }

        //打款凭证上传
        $imgPath = null;
        if ($request->hasFile('img') && $request->file('img')->isValid()) {
            $file = $request->file('img');
            //验证图片格式
            $ext = strtolower($file->getClientOriginalExtension());
            if ($ext !== "jpg" && $ext !== "jpeg" && $ext !== "png") {
                $this->data = $this->makeJsCode(1, "$ext" . "文件不允许上传，请选择JPG、JPEG、PNG格式图片！");
                return response()->json($this->data);
            }
            //重命名图片并移动到目录
            $filename = md5_file($file->getPathname()) . "." . $ext;   //md5 + 扩展名
            $file->move('uploads/proof-img/', $filename);
            $imgPath = 'uploads/proof-img/' . $filename;
        }

        if ($imgPath === null) {
            $this->data = $this->makeJsCode(1, "图片上传失败，请重试！");
            return response()->json($this->data);
        }

        $uname = $request->uname;
        $real_name = $request->name;
        $phone = $request->phone;
        $money = $request->money;
        $remark = $request->remark;

        //打款申请单保存
        if (MRemitLog::saveRemitLog($uname, $real_name, $phone, $money, $time, $remark, $imgPath, $request->remit_type, $info)) {
            $this->data = $this->makeJsCode(0, "操作成功！");
        } else {
            unlink(public_path() . '/' . $imgPath);
            $this->data = $this->makeJsCode(1, "操作失败！");
        }

        return response()->json($this->data);
    }

    public function remitLogs($index = 1)
    {
        $query = (new MRemitLog())->query();
        $query = $query->where('uid', $_SESSION['uid']);
        $this->fyInit(route('sys.remit.logs'), 15)->fyCalc($query->count(), $index);
        $this->data['logs'] = $query->skip($this->fy_pgOffset)->take($this->fy_pgSize)
            ->orderBy('status', 'asc')->orderBy('apply_time', 'desc')->get();
        $this->fyViewInit($this->data);
        return view('system.remit_logs')->with($this->data);
    }

    /**
     * 注册新会员界面
     */
    public function regUserPage($nid = 0)
    {
        $nuser = MUser::find($nid);
        $this->data['nuser'] = $nuser;
        return view('system.reg_user')->with($this->data);
    }

    /**
     * 会员列表
     * $flag = 1 未激活的报单会员
     * $flag = 2 已激活的报单会员
     * $flag = 3 我的推荐子会员
     */
    public function usersPage(Request $request, $flag, $index = 1)
    {
        //开启分页搜索支持
        $this->fyInit(route('sys.users', ['flag' => $flag]), 20, $request->getQueryString());
        $query = (new MUser())->query();

        if ($flag == 1) {
            $query = $query->where("ok_status", MUser::$STATUS_NOACTIVATED);

        } elseif ($flag == 2) {
            $query = $query->where("ok_status", MUser::$STATUS_ACTIVATED)->where("pid", ss('uid'));

        } elseif ($flag == 3) {
            $query = $query->where("pid", ss('uid'));
        }

        $this->fyCalc($query->count(), $index);
        $this->data['users'] = $query->skip($this->fy_pgOffset)
            ->take($this->fy_pgSize)->get();

        $this->data['flag'] = $flag;
        $this->fyViewInit($this->data);
        $this->data['flag'] = $flag;
        return view('system.users')->with($this->data);
    }

    /**
     * 申请报单中心界面
     */
    public function bdzxPage()
    {
        $this->data['user'] = MUser::find(ss('uid'));
        return view('system.apply_bdzx')->with($this->data);
    }

    /**
     * 申请报单中心逻辑处理
     */
    public function bdzxAct(Request $request)
    {
        $me = MUser::find(ss('uid'));
        if ($me->safepass != $request->safepass) {
            $this->data = $this->makeJsCode(1, '交易密码验证失败！');
            return response()->json($this->data);
        }

        //检查报单中心状态
        if ($me->bdzx_status == MUser::$BDZX_YES) {
            $this->data = $this->makeJsCode(1, '您已经是报单中心，不可重复开通！');
            return response()->json($this->data);
        }

        //检查账户余额
        $me_wallet = $me->wallet;
        if ($me_wallet->w1 < cache('kv_bdzx_money')) {
            $this->data = $this->makeJsCode(1, '您的账户余额不足！');
            return response()->json($this->data);
        }

        //开通报单中心
        try {
            DB::transaction(function () use (&$me) {
                if ($me->openBdzx(true)) {
                    $this->data = $this->makeJsCode(0, "开通成功！");
                } else {
                    DB::rollBack();
                    $this->data = $this->makeJsCode(1, "开通失败！");
                }
            });
        } catch (Exception $exception) {
            $this->data = $this->makeJsCode(1, "开通失败！");
        }
        return response()->json($this->data);
    }

    /**
     * 会员节点关系图
     */
    public function nodeTreePage($uid)
    {
        $user = MUser::find($uid);
        $me = MUser::find(ss('uid'));

        if (empty($user) || $user->ntree <= $me->ntree) {
            $this->data = $this->makeJsCode(1, "您无权查看您的上级会员！");
//            request()->ss()->flash('code', $this->data['code']);
//            request()->ss()->flash('msg', $this->data['msg']);
            $this->data['user'] = $me;
        } else {
            $this->data['user'] = $user;
        }
        return view('system.node_tree')->with($this->data);
    }

    /**
     * 会员推荐关系图
     */
    public function zTreePage()
    {
        $me = MUser::find(ss('uid'));

        $childs = new Collection();
        $childs->add($me);

        $cids = TreeUtil::getPChildsByUser($me);

        foreach ($cids as $cid) {
            $child = MUser::find($cid);
            $childs->add($child);
        }

        $this->data['user'] = $childs;

        return view('system.node_zTree')->with($this->data);
//        $me = MUser::find(ss('uid'));
//        $users = MUser::select(['id', 'username', 'pid'])->where('ptree', '>', $me->ptree)->get();
//        $childs = new Collection();
//        $childs->add($me);
//        //对用户进行筛选过滤
//        foreach ($users as $u) {
//            $curU = $u;
//            while (!empty($curU)) {
//                if ($curU->pid == $me->id) {
//                    $childs->add($u);
//                    break;
//                } else {
//                    $curU = $users->where('id', $curU->pid)->first();
//                }
//            }
//        }
//        $this->data['user'] = $childs;
//        return view('system.node_zTree')->with($this->data);
    }

    /**
     * 我的个人信息页面
     */
    public function myInfoPage()
    {
        $this->data['user'] = MUser::find(ss('uid'));
        return view('system.information')->with($this->data);
    }

    /**
     *  个人信息修改保存
     */
    public function myInfoSave(Request $request)
    {
        if (!$this->validateReq($request, MUser::myInfoRulesWithMsg(0), MUser::myInfoRulesWithMsg(1))) {
            $this->data = $this->makeJsCode(1, $this->errors->first());
            return response()->json($this->data);
        }

        $me = MUser::find(ss('uid'));
        if ($me->first == MUser::$FIRST_OK) { //判断是否修改过
            $this->data = $this->makeJsCode(1, '你已修改一次信息不可再次修改！');
            return response()->json($this->data);
        }

        if ($me->infoSave($request->email, $request->realname, $request->mobile, $request->receipt)) {
            $this->data = $this->makeJsCode(0, "修改成功！");
        } else {
            $this->data = $this->makeJsCode(1, "修改失败！");
        }
        return response()->json($this->data);
    }

    /**
     * 修改密码界面
     */
    public function modifyPassPage()
    {
        return view('system.modify_pass');
    }

    /**
     * 修改密码保存方法
     */
    public function modifyPassSave(Request $request)
    {
        if (!$this->validateReq($request, MUser::modifyPassRulesWithMsg(0), MUser::modifyPassRulesWithMsg(1))) {
            $this->data = $this->makeJsCode(1, $this->errors->first());
            return response()->json($this->data);
        }

        $me = MUser::find(ss('uid'));

        //判断是否修改登录密码
        if ($request->type == 1) {
            if ($request->oldpass != $me->userpass) {
                $this->data = $this->makeJsCode(1, '原密码验证失败!');
                return response()->json($this->data);
            }
        } elseif ($request->type == 2) {
            if ($request->oldpass != $me->safepass) {
                $this->data = $this->makeJsCode(1, '原密码验证失败!');
                return response()->json($this->data);
            }
        }

        if ($me->modifyPass($request->type, $request->newpass)) {
            $this->data = $this->makeJsCode(0, '修改密码成功!');
        } else {
            $this->data = $this->makeJsCode(0, '修改密码失败!');
        }

        return response()->json($this->data);
    }

    /**
     * 前台退出当前用户的登录
     */
    public function exitAct()
    {
        $user = new Muser;
        $user->loginStatus($bool = false);
        return redirect()->route('login.page');
    }

    /**
     * 找回密码操作
     */
    public function findPass(Request $request)
    {
        if (!$request->has('username')) {
            $this->data = $this->makeJsCode(1, "请输入您要查找的用户名！");
            return response()->json($this->data);
        }

        $user = MUser::where('username', $request->username)->first();
        if (empty($user) || empty($user->email)) {
            $this->data = $this->makeJsCode(1, "账户未绑定邮箱，无法找回！");
            return response()->json($this->data);
        }

        try {
            Mail::send('system.coms.findpass-template', ['user' => $user], function ($m) use ($user) {
                $m->subject("密码找回邮件，请查收！")
                    ->from(env('MAIL_USERNAME'), cv('website.site_name'))
                    ->to($user->email);
            });
            $this->data = $this->makeJsCode(0, "密码已发送至您的绑定邮箱！");
        } catch (Exception $e) {
            $this->data = $this->makeJsCode(1, "邮件发送失败，请重新尝试！");
        }

        return response()->json($this->data);
    }

}